unit fmCustomMultiSelect;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxContainer, cxEdit, dxSkinsCore, dxSkinOffice2007Black, Menus, cxStyles,
  dxSkinscxPCPainter, cxCustomData, cxFilter, cxData, cxDataStorage, DB,
  cxDBData, cxGridLevel, cxClasses, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
  StdCtrls, cxButtons, cxGroupBox, ActnList, DBAccess, Uni, MemDS,
  cxCheckBox;

type
  TCustomMultiSelectForm = class(TForm)
    tblSelect: TUniTable;
    dsSelect: TUniDataSource;
    CustomSelectActionList: TActionList;
    actSelect: TAction;
    actCancel: TAction;
    grpButtons: TcxGroupBox;
    btnApply: TcxButton;
    btnClose: TcxButton;
    pnlAll: TcxGroupBox;
    grdSelect: TcxGrid;
    grdSelectView: TcxGridDBTableView;
    grdSelectLevel1: TcxGridLevel;
    tblSelectIsChecked: TIntegerField;
    clmnIsChecked: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure actCancelExecute(Sender: TObject);
    procedure actSelectUpdate(Sender: TObject);
  private
    { Private declarations }
  protected
    FChanged: boolean;
    FId, FParId: integer;
    procedure Init; virtual;
  public
    { Public declarations }
    class function ExecuteId(AOwner: TComponent; ACurrentId: integer = -1; ACurrentParId: integer = -1): boolean;
  end;

implementation

{$R *.dfm}

{ TCustomMultiSelectForm }

class function TCustomMultiSelectForm.ExecuteId(AOwner: TComponent;
  ACurrentId: integer; ACurrentParId: integer): boolean;
begin
  with Create(AOwner) do
  try
    if ACurrentId > 0 then
      FId := ACurrentId
    else
      FId := -1;

    if ACurrentParId > 0 then
      FParId := ACurrentParId
    else
      FParId := -1;
    Init;
    Result := ShowModal = mrOk;
  finally
    Free;
  end;
end;

procedure TCustomMultiSelectForm.FormCreate(Sender: TObject);
begin
  tblSelect.Open;
end;

procedure TCustomMultiSelectForm.actCancelExecute(Sender: TObject);
begin
  Close;
end;

procedure TCustomMultiSelectForm.Init;
begin
//virtual
end;

procedure TCustomMultiSelectForm.actSelectUpdate(Sender: TObject);
begin
  if actSelect.Enabled <> FChanged then
    actSelect.Enabled := FChanged;
end;

end.
